﻿Public Class PrintPreviewForm
    Public NumberofPages As Integer
    Public NumberofRecords As Integer
    Public CurrentRecord As Integer


    Private Sub PrintPreviewForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ToolPanel.Height = ToolStrip1.Height
        PageLabel.Text = "Page 1 of " & NumberofPages

    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        Me.Close()

    End Sub

    Private Sub ToolStripButton6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton6.Click
        If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            PrintPreviewControl1.Document.PrinterSettings.PrinterName = PrintDialog1.PrinterSettings.PrinterName
            PrintPreviewControl1.Document.PrinterSettings.Copies = PrintDialog1.PrinterSettings.Copies
            PrintPreviewControl1.Document.Print()
        End If
    End Sub

    
    Private Sub PrintPreviewForm_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
        PageLabel.Text = "Page 1 of " & NumberofPages

    End Sub

    Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
        With PrintPreviewControl1
            If .StartPage < NumberofPages - 1 Then
                .StartPage = .StartPage + 1
                PageLabel.Text = "Page " & .StartPage + 1 & " of " & NumberofPages
            End If
        End With
    End Sub

    Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
        With PrintPreviewControl1
            If .StartPage > 0 Then
                .StartPage = .StartPage - 1
                PageLabel.Text = "Page " & .StartPage + 1 & " of " & NumberofPages
            End If
        End With
    End Sub

    Private Sub ToolStripButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton5.Click
        If CurrentRecord >= NumberofRecords Then Exit Sub

        CurrentRecord = CurrentRecord + 1

        RecordLabel.Text = "Record " & CurrentRecord & " of " & NumberofRecords

        ReportDesignerForm.LoadRecord(CurrentRecord)
        NumberofPages = 0
        PrintPreviewControl1.InvalidatePreview()

    End Sub

    Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click
        If CurrentRecord <= 1 Then Exit Sub

        CurrentRecord = CurrentRecord - 1

        RecordLabel.Text = "Record " & CurrentRecord & " of " & NumberofRecords

        ReportDesignerForm.LoadRecord(CurrentRecord)
        NumberofPages = 0
        PrintPreviewControl1.InvalidatePreview()

    End Sub
End Class